package com.library.uiframework.widget.actionbar;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.library.uiframework.R;

/**
 * action更多菜单 holderview
 * Created by louzhen on 15/12/26.
 */
public class ActionMenuListHolderView extends BaseHolderView {

    private TextView mTextView;
    private ImageView mIcon, mDot;

    /**
     * 构造方法
     * @param context 环境上下文
     */
    public ActionMenuListHolderView(Context context) {
        super(context, R.layout.uikit_action_menu_list_item);
    }

    @Override
    public void initView(View rootView) {
        mTextView = (TextView)rootView.findViewById(R.id.menu_list_item_text);
        mIcon = (ImageView)rootView.findViewById(R.id.menu_list_item_img);
        mDot = (ImageView)rootView.findViewById(R.id.menu_list_item_red_dot);

    }

    @Override
    public void bindData(IAdapterData data, int position) {
        if (data != null && data instanceof ActionMenuItem) {
            ActionMenuItem actionMenuItem = (ActionMenuItem) data;
            mTextView.setText(actionMenuItem.getName());
            if (actionMenuItem.getIconResId() > 0) {
                mIcon.setImageResource(actionMenuItem.getIconResId());
            } else {
                mIcon.setVisibility(GONE);
            }
            mDot.setVisibility(actionMenuItem.hasRedRot() ? VISIBLE : GONE);

            if (actionMenuItem.isSelected()) {
                mTextView.setTextColor(getResources().getColor(R.color.ykp_c10));
            } else {
                mTextView.setTextColor(getResources().getColor(R.color.ykp_c1));
            }
        }
    }
}
